import time

from selenium import webdriver
from selenium.webdriver.common.by import By

from unittest import TestCase


class TestLogin(TestCase):

    # 登陆成功用例
    def testLogin1(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10000"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

    def testLogin2(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10000"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[4]/a").click()
        # 个人中心
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[4]/ul/li[3]/a").click()
        # 银行卡管理
        time.sleep(2)



        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

        time.sleep(2)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "admin"
        password = "123456"
        expect = "后台管理系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[5]/a").click()
        # 网贷管理
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[5]/ul/li[1]/a").click()
        # 网贷审核
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[7]/button[1]").click()
        # 审核通过
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10000"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[4]/a").click()
        # 个人中心
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[4]/ul/li[3]/a").click()
        # 银行卡管理
        time.sleep(2)



        driver.quit()

    def testLogin3(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi5"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10000"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

    def testLogin4(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "100000000000000000"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

    def testLogin5(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10"
        qixian = "10"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

    def testLogin6(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10"
        qixian = "10000"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()

    def testLogin7(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"
        pay = "666666"
        jine = "10"
        qixian = "9999"
        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "/html/body/div/div/div/form/div[2]/input").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(3)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/a").click()
        # 金融工具
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[3]/ul/li[2]/a").click()
        # 安全网贷
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='amount']").send_keys(jine)
        # 输入金额
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='term']").send_keys(qixian)
        # 输借款期限
        time.sleep(2)

        driver.find_element(By.XPATH, "//*[@id='submit']").click()
        # 点击申请
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]").click()
        # 确定
        time.sleep(2)

        driver.quit()